# -*- coding: utf-8 -*-
# @Time        :2025/4/17 16:33
# @Author      :文刀水寿
# @File        : urls.py
"""
 @Description :
"""
from fastapi import APIRouter
from pydantic import BaseModel, Field, field_validator
from datetime import date
from typing import List, Union, Optional

app3 = APIRouter()


class Addr(BaseModel):
    province: str
    city: str


class User(BaseModel):
    name: str = Field(pattern="^a")  # 正则
    age: int = Field(default=0, gt=0, lt=100)  # gt大于 lt小于 default默认值
    birth: Union[None, date] = None
    friends: List[int] = []
    description: Optional[str] = None
    addr: Addr  # 类型嵌套

    @field_validator("name")
    def name_must_alpha(cls, value):
        assert value.isalpha(), 'name must alpha'
        return value


class Data(BaseModel):
    data: List[User]


@app3.post("/user")
async def data(user: User):  # user对象
    return user


# @app3.post("/data")
# async def date(date: Data):  # user对象
#     return date
